package com.wn.user.mapper;

import com.wn.common.pojo.AreaVillage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @BelongsProject: shared_parking
 * @BelongsPackage: com.wn.user.mapper
 * @Author: 廖刚
 * @CreateTime: 2020-06-17 21:38
 * @Description: 小区,地区表的持久化层
 */
public interface AreaVillageMappper {

    //判断有无该小区名存在
    @Select("select count(0) from area_village where a_name = #{aName} and parent_id != '0'")
    Integer existVillagerByAName(@Param("aName") String aName);

    //通过地区名获取地区id
    @Select("select a_id from area_village where a_name = #{aName}")
    String getIdByAreaName(@Param("aName") String aName);

    //向小区表中动态添加数据
    Integer addAreaVillage(AreaVillage areaVillage);


    //根据地区名得到地区下面所有的小区
    @Select("select * from area_village where parent_id in (select a_id from area_village where a_name = #{aName})")
    List<AreaVillage> getVillageByAreaName(@Param("aName") String aName);


    //根据父id得到下面所有的小区
    @Select("select * from area_village where parent_id = #{aid}")
    List<AreaVillage> getVillageByAId(@Param("aid") String aid);

    //通过名称获取对象
    @Select("select * from area_village where a_name = #{aName}")
    AreaVillage getAreaVillageByName(AreaVillage areaVillage);

    //查询所有的小区列表
    @Select("select * from area_village where parent_id != '0'")
    List<AreaVillage> getAllVillage();

    //通过小区id获取地区对象
    @Select("select * from area_village where a_id = (select parent_id from area_village where a_id = #{vId})")
    AreaVillage getAreaByVId(@Param("vId") String vId);

    //查询所有的除最近地区对象的地区列表
    @Select("select * from area_village where a_id != #{aId} and parent_id = '0'")
    List<AreaVillage> getAllAreaBesideOne(@Param("aId") String aId);

    //动态查询地区小区表
    List<AreaVillage> getListByAreaVillage(AreaVillage areaVillage);


}
